package com.sjqi.demo;


import org.junit.Test;

import java.sql.*;

/**
 * @author 完整的jdbc
 */
public class JdbcTest {
    @Test
    public void testJdbc() {
        String sql = "select * from t_invoice where id=?";
        Connection connection = null;
        PreparedStatement pStatement = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/pop_settlement?characterEncoding=utf-8", "root", "root");
            pStatement = connection.prepareStatement(sql);
            pStatement.setLong(1, 10892L);
            rs = pStatement.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getLong("id") + "====" + rs.getString("invoice_total_money"));
            }
        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (null != rs) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (null != pStatement) {
                try {
                    pStatement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (null != connection) {
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
